<?php
	$chkAll = $this->formCheckbox('chkAll', 0);
	
	//Tool bar
	$linkDisableItems = $this->baseUrl($this->currentController . '/hopthu/loaithu/' . $this->loaithu . '/delete/0');
	$btnDisableItems = $this->cmsButton('Xóa nhiều dòng', $linkDisableItems, $this->baseUrl(PUBLIC_PATH . "/img/toolbar/disable_user.png"), 'submit','multidelete');
	
	$frm_sendmail = $this->form_sendmailtoposter;
?>

<script type="text/javascript">
$(function(){
    // add multiple select / deselect functionality
    $("#chkAll").click(function () {
          $('.case').attr('checked', this.checked);
    });
    // if all checkbox are selected, check the selectall checkbox and viceversa
    $(".case").click(function() {
        if($(".case").length == $(".case:checked").length) {
            $("#chkAll").attr("checked", "checked");
        } else {
            $("#chkAll").removeAttr("checked");
        }
    });

    $("a.confirm-dialog").click(function(event){
		$( "#question" ).dialog("open");
	});
    
});
</script>

<div class="block">
	<div class="title">
		<span><?php echo $this->title; ?></span>
	</div>
	<div class="content">
		<div class="wrap-content">
			<div id="toolbar-box" class="toolbar">
				<div class="top-box">
					<div class="top-box">
						<div class="top-box"></div>
					</div>
				</div>
				<div class="m-box">
					<div class="icon-page title-users"></div>
					<?php echo $btnDisableItems;?>
					<div class="clear"></div>
				</div>
				<div class="bottom-box">
					<div class="bottom-box">
						<div class="bottom-box"></div>
					</div>
				</div>
			</div>
	    
	    	<?php if(count($this->items) > 0) { ?>
				<form name="appForm" action="" method="POST" style="margin-top: 5%;">
					<!-- Total items label -->
					<div class="row-func">
						<div class="number-items">
							<span><?php echo $this->totalItem;?> items</span>
						</div>
					</div>
					<table class="gridview" id="tinraotb">
						<thead>
							<tr>
								<th class="check-column"><?php echo $chkAll;?></th>
								<th><?php echo $this->from; ?></th>
								<th>Tiêu đề</th>
								<th>Nội dung</th>
								<th>Ngày</th>
								<th style="width: 100px">Thao tác</th>
							</tr>
						</thead>
						<tbody>
							<?php
								foreach($this->items as $key => $val) {
									$id    		 = $val->id;
									$from        = $val->nguoi_gui;
									$title       = $val->tieu_de;
									$content	 = strip_tags($val->noi_dung);
									$date		 = $val->getNgay_gui('d-m-Y H:i:s');
									
									$chkid   	 = $this->formCheckbox('cid[]', $id, array('class' => 'case'));
									
									$txtFrom = '<td>Vô danh</td>';
									$htmlReply = '';
									if ($from != 0) {
										$user = new Default_Model_UsersMapper();
								        $user_obj = $user->fetchAll('id = '. $from, 'view');
										$txtFrom = '<td>' . $user_obj->email . '</td>';
									}
									
									//Action button
									$action = '<div class="btn-group dropup">
													<button class="btn btn-primary btn-mini" data-toggle="dropdown" >
														<i class="icon-ok-circle icon-white"></i>Chức năng
													</button>
							    					<button class="btn btn-primary btn-mini dropdown-toggle" data-toggle="dropdown">&nbsp;
						                               <span class="caret"></span>
						                            </button>
							    					<ul class="dropdown-menu">
									                	<li><a class="" href="/member/hopthu/loaithu/' . $this->loaithu . '/view/' . $id . '"><i class="cus-eye"></i>Xem</a><li>
									                	<li><a class="confirm-dialog" onclick="return confirmDialog(this, \'/member/hopthu/loaithu/' . $this->loaithu . '/delete/' . $id . '\');" href="#"><i class="cus-email_delete"></i>Xóa</a><li>
									                </ul>
									           </div>';
									
									$row = '<tr>';
									if ($val->da_xem == 1) 
										$row = '<tr class = "viewed">';
									echo $row;
									echo '<th class="check-column" scope="row">' . $chkid . '</th>';
									echo $txtFrom;
									echo '<td title="' . $title . '">' . Zendhlt_Encode::truncateString_($title, 20) . '</td>';
									echo '<td title="' . $content . '">' . Zendhlt_Encode::truncateString_($content, 20) . '</td>';
									echo '<td class="cell-padding">' . $date . '</td>';
									echo '<td align="center">' . $action.'</td>';
									echo '</tr>';
								}
							?>
						</tbody>
						<!-- BEGIN: PAGINATION (FOOT) -->
						<tfoot>
							<tr>
								<td colspan="6">
									<div class="pagination">
										<?php
											$currentUrl = $this->baseUrl($this->currentController . '/hopthu/loaithu/' . $this->loaithu);
											echo $this->paginationControl($this->panigator, 'Sliding', 'pagination.phtml', array('currentUrl' => $currentUrl));
										?>
									</div>
								</td>
							</tr>
						</tfoot>
						<!-- END: PAGINATION (FOOT) -->
					</table>
					<div class="clear"></div>
				</form>
				<div class="dialog" id="question">
					<img src="<?php echo $this->baseUrl(PUBLIC_PATH . '/img/question.png'); ?>" alt="question" />
					<p>Bạn có chắc chắn muốn xóa không?</p>
				</div>
			<?php } else { echo '<p class="no-info">Chưa có tin nhắn nào.</p>'; }?>
			<br class="clear" />
		</div>
	</div>
	<br class="clear" />
</div>